<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        {{user}}
        <button @click="addFiled">添加身高</button>
        <br/>
        {{cat}}
        <button @click="addCat">猫</button>
    </div>
</body>
<script src="../js/http_cdn.bootcdn.net_ajax_libs_vue_2.6.6_vue.js"></script>
<script>
    // https://www.cnblogs.com/ljy-/articles/12712645.html Vue.js 不能检测到对象属性的添加或删除,
    // https://blog.csdn.net/valentinelzt/article/details/108163455
    new Vue({
        el: "#app",
        data: {
            user:{
                name: "张三",
                age: "18"
            },
            cat:{

            }

        },
        methods: {
            addFiled() {
                // this.user.height = " 180"
                this.$set(this.user,'height',"180")
                console.log(this.user)
            },
            addCat(){
                let cat = {
                    name: "小灰",
                    age: "18"
                }

                // 如果直接拷贝对象不会发生不触发双向绑定的情况
                // this.cat = {...cat}
                this.cat = JSON.stringify(cat)
            }
        },
    })
</script>

</html>
